import datetime
import sys
import traceback

class Utils(object):
    """description of class"""
    @staticmethod
    def convertNumberToDateString(num):
        '''
        Convert js date number to date string format 'yyyy-MM-dd'

        Examples: convertNumberToDateString(1395014400000)
        >>>2014-03-17
        '''
        if num and num > 0:
            return datetime.date.fromtimestamp(num/1000).strftime("%Y-%m-%d")
        else:
            return None

    @staticmethod
    def convertBoolStrToBit(str):
        '''
        Convert bool string to bit 
        '''
        if str == "true" or str == True:
            return 1
        return 0

    @staticmethod
    def format_exception():
        '''
        return the string with full stack for last exception
        '''
        exc_type, exc_value, exc_traceback = sys.exc_info()
        lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
        return ''.join(line for line in lines)
